<?php
/**
 * Feedback_AdminController
 * 
 * @author
 * @version 
 */
 
class Feedback_AdminController extends Zen_Controller_Admin
{
	public $columns =  array(
                       	array('name'=>'id','index'=>'id','label'=>'ID','width'=>30),
                       	array('name'=>'email','index'=>'email','label'=>'Email'),
                       	array('name'=>'date','index'=>'date','label'=>'Дата',
                       		 'formatter'=>'date','formatoptions'=>array('date'=>array('srcformat'=>'Y-m-d H:i:s','newformat'=>'d.m.Y H:i:s'))
                       	));
    
	public function init() {
		parent::init();
		$this->model = new Feedback_Model_Item();
	}
	
	
    public function indexAction() {
		$this->view->model = $this->model; 
		$this->view->columns = $this->columns;
		$this->_helper->layout->setLayout('admin');
	}
	
	public function formAction(){
		$params=$this->_getAllParams();
		$this->_helper->jqgrid(
    		$this->model,
    		$params,
    		$this->columns,
    		new Feedback_Form_Contact()
    	);
	}
	
    public function settingsAction(){
       $form = new Feedback_Form_Settings();
       $cnf = new Zend_Config_Ini(ROOT_PATH.'/site/modules/feedback/settings/feedback.ini');    
       $form->setDefaults($cnf->toArray());
       if ($this->_request->isPost()) {
            if($form->isValid($this->_getAllParams())){
                $writer = new Zend_Config_Writer_Ini();
                $cnf = new Zend_Config($form->getValues());
                $writer->write(ROOT_PATH.'/site/modules/feedback/settings/feedback.ini',$cnf);
                $this->_helper->FlashMessenger->setNamespace('messages')->addMessage(array('text'=>'Настройки сохранены','type'=>'alert'));
                $this->_redirect($_SERVER['REQUEST_URI']);
            }
        }
        $this->view->form = $form;
    }
    
	public function showAction(){
		$this->_helper->layout->disableLayout();
		$id = preg_replace('/\D/', '',$this->_getParam('id'));
		$model =	$this->model;
		$item = $model->select()->getOne("id='".$id."'");
		$this->view->item = $item;
	}
	
}